import { NextApiRequest, NextPageContext } from 'next';
import { AppContext, AppInitialProps, NextWebVitalsMetric } from 'next/app';
import { CssBaseline, GeistProvider } from '@geist-ui/react';
import { SWRConfig } from 'swr';
import anylogger from 'anylogger';
import Framelayout from './framelayout';
import '../../styles/globals.css';
import '../../styles/vars.css';
import 'antd/dist/antd.css';
import '@arco-design/web-react/dist/css/arco.css';

const logger = anylogger('app');

export function reportWebVitals(metric: NextWebVitalsMetric) {
	logger.info(metric);
}

function App({ Component, pageProps, router }: AppInitialProps & AppContext) {
	const pathname = router.pathname;
	const ispublic = /^\/public/.test(pathname);
	return (
		<SWRConfig
			value={{
				// refreshInterval: 10000,
				async fetcher(url: string) {
					const res = await fetch(url);
					return res.json();
				},
			}}
		>
			<GeistProvider>
				<CssBaseline />
				{/* <Component {...pageProps} /> */}
				{ispublic ? (
					<Component {...pageProps} />
				) : (
					<Framelayout pathname={pathname}>
						<Component {...pageProps} />
					</Framelayout>
				)}
			</GeistProvider>
		</SWRConfig>
	);
}

export default App;
